package com.sykj.qianxuezhan.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sykj.qianxuezhan.bean.Shop;
import com.sykj.qianxuezhan.bean.ShopUser;
import com.sykj.qianxuezhan.server.ShopService;
import com.sykj.util.reponse.CommonEnum;
import com.sykj.util.reponse.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author QianXuezhan
 * @Date 2020/7/19 15:27
 * @Description: TODO
 */

@CrossOrigin
@RestController
@RequestMapping("/shop1")
public class ShopController {

    @Autowired
    private ShopService shopService;

    /**
     * @Date:
     * @Description: 查询所有综合查询
     **/
    @RequestMapping(value = "/queryShop1",method = RequestMethod.GET)
    public List<Shop> queryShop(){

        return  shopService.queryShop();
    }


    /**
     * @Date:
     * @Description:   假删除店铺信息
     **/
    @RequestMapping(value = "/updateShopDelId",method = RequestMethod.POST)
    public ResultBody updateShopDelId(String shopId){
        UpdateWrapper queryWrapper=new  UpdateWrapper();
        queryWrapper.eq("shop_id",shopId);
        queryWrapper.set("is_del",1);
        shopService.update(queryWrapper);
        return  new ResultBody(CommonEnum.SUCCESS);
    }

    /**
     * @Date:
     * @Description: 修改店铺信息
     **/
    @RequestMapping(value = "/updateShop1",method = RequestMethod.POST)
    public ResultBody  updateShop(Shop shop,String shopIntro,String  shopRemark){

        System.out.println(shop.getShopType()+"-------"+shop);
        shop.setShopIntro(shopIntro);
        shop.setShopRemark(shopRemark);
        shopService.updateShop(shop);
        return  new ResultBody(CommonEnum.SUCCESS);
    }


    /**
     * @Date:
     * @Description:  添加店铺信息
     **/
    @RequestMapping(value = "/saveShop",method = RequestMethod.POST)
    public ResultBody saveShop(Shop shop,String shopIntro,String  shopRemark){
       shop.setShopId(Long.toString(System.currentTimeMillis()));
        shop.setShopIntro(shopIntro);
        shop.setShopRemark(shopRemark);
       shopService.saveShop(shop);
        return  new ResultBody(CommonEnum.SUCCESS);
    }

    //通过店主账户查询店主id和姓名
    @RequestMapping(value = "/queryShopUserAcc",method = RequestMethod.POST)
    public Map queryShopUserAcc(String account){
        Map map = new HashMap();
         ShopUser shopUser= shopService.queryShopUserAcc(account);
         if(shopUser!=null){
             map.put("pd","0");
             map.put("shopUserId",shopUser.getShopUserId());
             map.put("username",shopUser.getUsername());
         }else{
             map.put("pd","1");
         }

        return  map;
    }


}
